package com.webbei.Backstage.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.webbei.Backstage.service.BackstateSer;
import com.webbei.pojo.Managers;
import com.webbei.pojo.OrderStatistics;
import com.webbei.pojo.Orders;
import com.webbei.pojo.RefundOrder;

public class OrderStatisticsAction extends ActionSupport {
	private BackstateSer bao;  
	 private String startTime;
     private String endTime;
     private String orstate;
     private String mark;
     private Integer productId;
     private String tradeId;
     private List<RefundOrder>refundOrders;
     private Float refundFee;
     private Float refundTotal;
     
     private List<OrderStatistics>orderStatistics;
     public String execute(){
    	 
		Managers mana = (Managers) ActionContext.getContext().getSession().get("mana");
		   Integer indusId = mana.getIndustryId();
		Map<String,Object>m = new HashMap<String, Object>();
    	 if("".equals(orstate)){
 			orstate=null;
 		}
 		
 		if("".equals(startTime)){
 			startTime=null;
 		}
 		if("".equals(endTime)){
 		    endTime=null;	
 		}
 	
 		if("".equals(mark)){
 			mark=null;
 		}
 		if(mark!=null){
 			String[]marks = mark.split("，|,|[ \t]+");
 			mark = "";
 			for(int i=0;i<marks.length;i++){
 				String s = marks[i];
 				if(i==0){
 					mark += s;
 				}else{
 					mark+="|"+s;
 				}
 				
 			}
 		}
 		  m.put("tradeId", tradeId);
 		  m.put("startTime", startTime);
 	      m.put("endTime", endTime);
 	      m.put("indusid", indusId);
 	      m.put("orstate", orstate);
 	      m.put("mark", mark);
 	      ServletActionContext.getRequest().getSession().setAttribute("query",m);
 	     orderStatistics = bao.getOrderStatistics(m);
 	     refundOrders = bao.getRefundOrder(m);
 	    refundFee = 0.0f;
 	    refundTotal = 0.0f;
 	     for(RefundOrder ro:refundOrders){
 	    	 refundFee += Float.parseFloat(ro.getRefundFee());
 	    	refundTotal += (Float.parseFloat(ro.getTotalFee()))*(ro.getNum());
 	     }
 	     System.out.println(refundFee+","+refundTotal);
    	 return "success";
     }
	public String getStartTime() {
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public String getOrstate() {
		return orstate;
	}
	public void setOrstate(String orstate) {
		this.orstate = orstate;
	}
	public String getMark() {
		return mark;
	}
	public void setMark(String mark) {
		this.mark = mark;
	}
	public Integer getProductId() {
		return productId;
	}
	public void setProductId(Integer productId) {
		this.productId = productId;
	}
	public String getTradeId() {
		return tradeId;
	}
	public void setTradeId(String tradeId) {
		this.tradeId = tradeId;
	}
	public List<OrderStatistics> getOrderStatistics() {
		return orderStatistics;
	}
	public void setOrderStatistics(List<OrderStatistics> orderStatistics) {
		this.orderStatistics = orderStatistics;
	}
	public void setBao(BackstateSer bao) {
		this.bao = bao;
	}
	public Float getRefundFee() {
		return refundFee;
	}
	public void setRefundFee(Float refundFee) {
		this.refundFee = refundFee;
	}
	public Float getRefundTotal() {
		return refundTotal;
	}
	public void setRefundTotal(Float refundTotal) {
		this.refundTotal = refundTotal;
	}
}
